
//
//  ZWTools.m
//  ZhengWeiZhongYi
//
//  Created by apple on 17/6/10.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "ZWTools.h"

#import "HGNetworkingRequest.h"
#import "MBProgressHUD+KR.h"
#import "CLTabBarViewController.h"
#import "AppDelegate.h"

@implementation ZWTools

+ (ZWTools *)sharedManager
{
    static ZWTools *sharedAccountManagerInstance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        sharedAccountManagerInstance = [[self alloc] init];
    });
    return sharedAccountManagerInstance;
}

//***********************************************用户************************************
//获取短信验证码
- (void) getPhoneCodeFromNetWorkingID:(NSString *)phone sucessBlock: (ScuessBlock)sucessBlock Error:(ErrorBlock) erroBlock{
    
    //获取nEwsType
    NSMutableDictionary *requestParameter = [NSMutableDictionary dictionary];
    requestParameter[@"phone"] = phone;
 
    [[HGNetworkingRequest shareRequest] startGetRequest:api_get_validate_code parameter:requestParameter showNetworkErrorAlert:YES onCompletion:^(id jsonResponse) {
        
        NSLog(@"sucess  %@", jsonResponse);
        NSString *result = [jsonResponse objectForKey:@"code"];
        NSLog(@"%@", result);
        
        if ([result isEqualToString:@"0000"]) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                 sucessBlock(jsonResponse);
                [MBProgressHUD showSuccess:@"获取验证码成功"];
                
                
            });
        } else if ([result isEqualToString:@"100"]) {
            
            [MBProgressHUD showSuccess:@"获取验证码失败"];
        }
        
    } onError:^(id jsonResponse) {
        erroBlock(jsonResponse);
       
         NSLog(@"error  %@", jsonResponse);
        
    }];
}

//注册
- (void)regist:(NSDictionary *)registDic sucessBlock:(ScuessBlock)sucessBlock Error:(ErrorBlock)erroBlock {
    
    NSMutableDictionary *requestParameter = [NSMutableDictionary dictionary];
    requestParameter = registDic.mutableCopy;
    
   [ [HGNetworkingRequest shareRequest] startPostRequest:api_user_register parameter:requestParameter showNetworkErrorAlert:YES onCompletion:^(id jsonResponse) {
       
      
       NSString *msg = [jsonResponse objectForKey:@"msg"];
       NSLog(@"%@", msg);
       [MBProgressHUD showSuccess:msg];
       
     NSInteger result = [[jsonResponse objectForKey:@"code"] integerValue];
       if (result == 0) {
           
           dispatch_async(dispatch_get_main_queue(), ^{
               sucessBlock(jsonResponse);
              
           });
       } else if (result == 100) {
           dispatch_async(dispatch_get_main_queue(), ^{
               sucessBlock(jsonResponse);
               
           });
           
           
       }
       
    } onError:^(id jsonResponse) {
        
    }];
}

//保存用户昵称
- (void)editUserNickName:(NSDictionary *)registDic sucessBlock: (ScuessBlock)sucessBlock Error:(ErrorBlock) erroBlock {
    
    NSMutableDictionary *requestParameter = [NSMutableDictionary dictionary];
    requestParameter = registDic.mutableCopy;
    
    [[HGNetworkingRequest shareRequest]  startPostRequest:api_user_editUserNickName  parameter:requestParameter showNetworkErrorAlert:YES onCompletion:^(id jsonResponse) {
        
        NSLog(@"%@", jsonResponse);
        
        NSString *result = [jsonResponse objectForKey:@"code"];
        if ([result isEqualToString:@"0000"]) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                sucessBlock(jsonResponse);
                
                [MBProgressHUD showSuccess:@"设置昵称成功"];
            });
        } else if ([result isEqualToString:@"100"]) {
            erroBlock(jsonResponse);
            
             [MBProgressHUD showSuccess:@"设置昵称失败"];
        }
        
    } onError:^(id jsonResponse) {
        
         NSLog(@"error  %@", jsonResponse);
        
    }];
}

//登录
-  (void)login:(NSDictionary *)registDic sucessBlock: (ScuessBlock)sucessBlock Error:(ErrorBlock) erroBlock {
    
    NSMutableDictionary *requestParameter = [NSMutableDictionary dictionary];
    requestParameter = registDic.mutableCopy;
    [[HGNetworkingRequest shareRequest] startGetRequest:api_user_login parameter:requestParameter showNetworkErrorAlert:YES onCompletion:^(id jsonResponse) {
        NSLog(@"sucess  %@", jsonResponse);
        
        NSInteger result = [[jsonResponse objectForKey:@"code"] integerValue];
       
        if (result == 0) {
            
            [MBProgressHUD showSuccess:@"登录成功"];
            BOOL is_Ic = NO;
            dispatch_async(dispatch_get_main_queue(), ^{
               
             sucessBlock(jsonResponse);
            });
        } else if (result == 100) {
           
            dispatch_async(dispatch_get_main_queue(), ^{
                
                 sucessBlock(jsonResponse);
                NSString *msg = [jsonResponse objectForKey:@"msg"];
                [MBProgressHUD showSuccess:msg];
                
                
            });
        }
        
      
        
    } onError:^(id jsonResponse) {
        
    }];
}

//找回密码验证
- (void)doFindUser:(NSDictionary *)registDic sucessBlock: (ScuessBlock)sucessBlock Error:(ErrorBlock) erroBlock {
    
    NSMutableDictionary *requestParameter = [NSMutableDictionary dictionary];
    requestParameter = registDic.mutableCopy;
    
    [[HGNetworkingRequest shareRequest] startGetRequest:api_user_doFindUser parameter:requestParameter showNetworkErrorAlert:YES onCompletion:^(id jsonResponse) {
        
        NSLog(@"%@", jsonResponse);
        NSString *result = [jsonResponse objectForKey:@"code"];
        if ([result isEqualToString:@"0000"]) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                sucessBlock(jsonResponse);
                [MBProgressHUD showSuccess:@"操作成功"];
                
            });
        } else if ([result isEqualToString:@"100"]) {
            
            [MBProgressHUD showSuccess:@"操作失败"];
        }
        
        
    } onError:^(id jsonResponse) {
        
    }];
    
}

//获得收款地址列表
- (void)getPaymentAddressList:(NSDictionary *)registDic sucessBlock: (ScuessBlock)sucessBlock Error:(ErrorBlock) erroBlock {
    
    [[HGNetworkingRequest shareRequest] startGetRequest:api_user_getPaymentAddressList parameter:nil showNetworkErrorAlert:YES onCompletion:^(id jsonResponse) {
         NSLog(@"%@", jsonResponse);
        NSInteger result = [[jsonResponse objectForKey:@"code"] integerValue];
        
        if (result==0) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                sucessBlock(jsonResponse);
                [MBProgressHUD showSuccess:@"操作成功"];
                
            });
        } else if (result ==4005) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                sucessBlock(jsonResponse);
                [MBProgressHUD showSuccess:[jsonResponse objectForKey:@"msg"]];
                
            });
        }
        
    } onError:^(id jsonResponse) {
        
    }];
}

//增加收款地址
- (void)addPaymentAddress:(NSDictionary *)registDic sucessBlock: (ScuessBlock)sucessBlock Error:(ErrorBlock) erroBlock {
    
    NSMutableDictionary *requestParameter = [NSMutableDictionary dictionary];
    requestParameter = registDic.mutableCopy;
    
    [[HGNetworkingRequest shareRequest] startPostRequest:api_user_addPaymentAddress parameter:requestParameter showNetworkErrorAlert:YES onCompletion:^(id jsonResponse) {
        
        NSLog(@"%@", jsonResponse);
        NSInteger result = [[jsonResponse objectForKey:@"code"] integerValue];
        
        if (result==0) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                sucessBlock(jsonResponse);
                [MBProgressHUD showSuccess:@"操作成功"];
                
            });
        } else if (result==100) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                sucessBlock(jsonResponse);
                [MBProgressHUD showSuccess:@"操作失败"];
                
            });
        }
        
        
    } onError:^(id jsonResponse) {
        
    }];
}

//获取收币地址
- (void)getCoinAddressList:(NSDictionary *)registDic sucessBlock: (ScuessBlock)sucessBlock Error:(ErrorBlock) erroBlock {
    
    NSMutableDictionary *requestParameter = [NSMutableDictionary dictionary];
    requestParameter = registDic.mutableCopy;
    
    [[HGNetworkingRequest shareRequest] startGetRequest:api_user_getCoinAddressList parameter:requestParameter showNetworkErrorAlert:YES onCompletion:^(id jsonResponse) {
        
        NSLog(@"%@", jsonResponse);
        NSInteger result = [[jsonResponse objectForKey:@"code"]integerValue];
        
        if (result==0) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                sucessBlock(jsonResponse);
                [MBProgressHUD showSuccess:@"操作成功"];
                
            });
        } else if (result==100) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                sucessBlock(jsonResponse);
                [MBProgressHUD showSuccess:[jsonResponse objectForKey:@"msg"]];
                
            });
        }
        
    } onError:^(id jsonResponse) {
        
    }];
}

//新增收币地址
- (void)addCoinAddress:(NSDictionary *)registDic sucessBlock: (ScuessBlock)sucessBlock Error:(ErrorBlock) erroBlock {
    
    NSMutableDictionary *requestParameter = [NSMutableDictionary dictionary];
    requestParameter = registDic.mutableCopy;
    
    [[HGNetworkingRequest shareRequest] startPostRequest:api_user_addCoinAddress parameter:requestParameter showNetworkErrorAlert:YES onCompletion:^(id jsonResponse) {
        
        NSLog(@"%@", jsonResponse);
        NSInteger result = [[jsonResponse objectForKey:@"code"]integerValue];
        
        if (result==0) {
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                sucessBlock(jsonResponse);
                [MBProgressHUD showSuccess:@"操作成功"];
                
            });
        } else if (result==100) {
            dispatch_async(dispatch_get_main_queue(), ^{
                
                sucessBlock(jsonResponse);
                 [MBProgressHUD showSuccess:@"操作失败"];
                
            });
           
        }
        
    } onError:^(id jsonResponse) {
        
    }];
}

//***********************************************中介************************************
//登录
- (void)icLogin:(NSDictionary *)registDic sucessBlock: (ScuessBlock)sucessBlock Error:(ErrorBlock) erroBlock {
    
        NSMutableDictionary *requestParameter = [NSMutableDictionary dictionary];
        requestParameter = registDic.mutableCopy;
        [[HGNetworkingRequest shareRequest] startGetRequest:api_ic_login parameter:requestParameter showNetworkErrorAlert:YES onCompletion:^(id jsonResponse) {
            NSLog(@"sucess  %@", jsonResponse);
           
       sucessBlock(jsonResponse);
            
        } onError:^(id jsonResponse) {
            
        }];
    
}

@end
